home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Mac-Source 1994 July
/
Mac-Source_July_1994.iso
/
C and C++
/
Science⁄Math
/
Scientist's Helper src
/
s.helper.3
/
reggraph.c
< prev
next >
Wrap
C/C++ Source or Header
|
1986-02-05
|
6KB
|
319 lines
#include "all.h"
#include "regtabext.h"
NextNotNan(startRow, x, y, foundRow)
int startRow, x, y, *foundRow;
/*searches through two columns of table, and returns first row after*/
/*and including startRow that has no Nans in the columns*/
{
int i, bothNaN;
float fx, fy;
*foundRow = 0;
bothNaN=TRUE;
for (i=startRow; ((i<=table.header.rows) && bothNaN); i++ ) {
GetTable( i, x, &fx );
GetTable( i, y, &fy );
if( (!NaN(&fx)) && (!NaN(&fy)) ) {
*foundRow = i;
bothNaN = FALSE;
} /* end if */
} /*end for*/
return(!bothNaN);
}
GraphScale( x, y, ix, iy ) /*to pixel coordinates*/
float x, y;
int *ix, *iy;
{
float xs, ys;
xs = ((float)(grXMax-grXMin))*(x-graph.xMin)/(graph.xMax-graph.xMin);
ys = ((float)(grYMin-grYMax))*(y-graph.yMin)/(graph.yMax-graph.yMin);
xs = xs + (float)grXMin;
ys = (float)grYMin-ys;
if( (xs>=(-32760.0)) && (xs<=32760.0) ) {
*ix=(int)xs;
}
else if( xs<(-32760.0) ) {
*ix = -32760;
}
else {
*ix = 32760;
}
if( (ys>=(-32760.0)) && (ys<32760.0) ) {
*iy=(int)ys;
}
else if( ys<(-32760) ) {
*iy = -32760;
}
else {
*iy = 32760;
}
}
InvGraphScale( ix, iy, x, y) /*pixels to graph coordinates*/
int ix, iy;
float *x, *y;
{
ix = ix-grXMin;
iy = grYMin-iy;
*x =( ( (float)(ix) / ((float)(grXMax-grXMin)) ) * (graph.xMax-graph.xMin) ) + graph.xMin;
*y =( ( (float)(iy) / ((float)(grYMin-grYMax)) ) * (graph.yMax-graph.yMin) ) + graph.yMin;
}
PlotCol()
{
int xcol, ycol, firstRow, nextRow, i, j, oldWindow, width;
int startRow, endRow, dx, dy, continuous, pat, refresh;
float x1, y1;
char symbol, s[cmdWordLen];
GrafPtr oldPort;
SToI( command.cmdWord[1], &xcol );
SToI( command.cmdWord[2], &ycol );
if (GoodCol(xcol)!=0) {
ErrMsg("bad x col");
}
if (GoodCol(ycol)!=0) {
ErrMsg("bad y col");
}
if( table.header.rows >= 1000 ) {
refresh = 100;
}
else {
refresh = 10;
}
strcpy( s, command.cmdWord[3] );
pat=0;
width=1;
if( (strlen(s)==0) || (strcmp(s,"solid")==0) ){
continuous =TRUE;
pat=0; /*black*/
width=1;
}
else if (strcmp(s,"dashed")==0) {
continuous =TRUE;
width=2;
pat=1; /*gray*/
}
else if (strcmp(s,"dotted")==0) {
continuous = TRUE;
pat=2; /*ltGray*/;
width=2;
}
else if (strcmp(s,"bold")==0) {
continuous = TRUE;
pat=0; /*black*/
width=2;
}
else if (strcmp(s,"dots")==0) {
continuous =FALSE;
dx=2;
dy =1;
symbol='.';
}
else if (strcmp(s,"crosses")==0) {
continuous=FALSE;
symbol = '+';
dx=2;
dy=5;
}
else if (strcmp(s,"circles")==0) {
continuous = FALSE;
symbol = 'o';
dx = 3;
dy = 3;
}
else if (strcmp(s,"stars")==0) {
continuous = FALSE;
symbol = '*';
dx = 2;
dy = 5;
}
else if (strcmp(s,"x")==0) {
continuous = FALSE;
symbol = 'x';
dx = 2;
dy = 3;
}
else {
ErrMsg("bad plotting symbol");
}
GetPort( &oldPort );
oldWindow=currentWindow;
SetPort(grPortPtr);
TextFont(monaco);
TextSize(9);
if( pat==1 ) {
PenPat( gray );
}
else if( pat==2 ) {
PenPat( ltGray );
}
else {
PenPat( black );
}
PenSize( width, width );
/*determine limits: dont plot interpolated data outside box*/
if( (table.header.interpolated) && (xcol==1) ) {
x1=1.0 + (graph.xMin-table.header.start)/table.header.samp;
if ((x1-1.0)<1.0) {
startRow =1;
}
else if ((x1-1.0)>((float)table.header.rows)) {
startRow = table.header.rows;
}
else {
startRow = (int)(x1-1.0);
}
x1 = 1.0 + (graph.xMax-table.header.start)/table.header.samp;
if( (x1+1.0)<1.0 ) {
endRow=1;
}
else if( (x1+1.0)>((float)table.header.rows) ) {
endRow=table.header.rows;
}
else {
endRow = (int)(x1+1.0);
}
}
else {
startRow =1;
endRow = table.header.rows;
}
if( NextNotNan(startRow,xcol,ycol, &firstRow) ) {
GetTable( firstRow, xcol, &x1 );
GetTable( firstRow, ycol, &y1 );
GraphScale( x1, y1, &i, &j );
if (continuous) {
MoveTo( i, j );
}
else {
MoveTo( i-dx, j+dy );
DrawText(&symbol, 0, 1);
}
firstRow++;
while( (firstRow<=endRow) && NextNotNan(firstRow,xcol,ycol,&nextRow) ) {
GetTable( nextRow, xcol, &x1 );
GetTable( nextRow, ycol, &y1 );
GraphScale( x1, y1, &i, &j );
if (continuous) {
LineTo( i, j );
}
else {
MoveTo( i-dx, j+dy );
DrawText(&symbol,0,1);
}
firstRow=nextRow + 1;
if( (nextRow%refresh)==0) {
CheckAbortMenu();
currentWindow=grWindow;
whichWindow=theWindow[grWindow];
SetPort( whichWindow );
DrawWindow();
SetPort( grPortPtr );
}
} /*end while*/
} /*end if*/
SetPort( theWindow[grWindow] );
InvalRect( &(theWindow[grWindow]->portRect) );
SetPort( oldPort );
currentWindow=oldWindow;
whichWindow=theWindow[currentWindow];
}
ClearGraph()
{
int oldWindow;
GrafPtr oldPort;
GetPort( &oldPort );
oldWindow=currentWindow;
SetPort( grPortPtr );
EraseRect( &(grPort.portRect) );
FrameRect(&(grPort.portRect) );
SetPort( theWindow[grWindow] );
InvalRect( &(theWindow[grWindow]->portRect) );
SetPort( oldPort );
currentWindow=oldWindow;
whichWindow=theWindow[currentWindow];
}
PlotAxes()
{
int i, ii, j, k, width, slen;
float x, interval;
char s[cmdWordLen];
int oldWindow;
GrafPtr oldPort;
Rect tRect;
GetPort( &oldPort );
oldWindow=currentWindow;
SetPort( grPortPtr );
PenPat( black );
PenSize(1,1);
TextFont(monaco);
TextSize(9);
SetRect( &tRect, 1, 1, (grXMin-1), (windowHeight-1) );
EraseRect(&tRect);
SetRect( &tRect, 1, (grYMin+1), (windowWidth-1), (windowHeight-1) );
EraseRect(&tRect);
MoveTo( grXMin, grYMin ); /*x axis*/
LineTo( grXMax, grYMin );
MoveTo( grXMin, grYMin); /*y axis*/
LineTo( grXMin, grYMax);
interval = (graph.yMax-graph.yMin)/5.0;
for( i=0; i<=5; i++ ) {
x=graph.yMin + (float)(i)*interval;
GraphScale(graph.xMin,x,&k,&j);
MoveTo( grXMin, j );
LineTo( (grXMin+6), j );
RToS( x, s );
MoveTo( 5, (j+4) );
DrawText( s, 0, strlen(s) );
}
interval = (graph.xMax-graph.xMin)/5.0;
for (i=0; i<=5; i++ ) {
x=graph.xMin + (float)(i)*interval;
GraphScale(x,graph.yMin,&j,&k);
MoveTo( j, grYMin);
LineTo( j, (grYMin-6) );
RToS( x, s );
width=0;
slen=strlen(s);
for( ii=0; ii<slen; ii++) {
width+=CharWidth(s[ii]);
}
MoveTo( (j-(width/2)), (grYMin+15) );
DrawText( s, 0, slen );
}
SetPort( theWindow[grWindow] );
InvalRect( &(theWindow[grWindow]->portRect) );
SetPort( oldPort );
currentWindow=oldWindow;
whichWindow=theWindow[currentWindow];
}